package yagwl.client.widget;

import yagwl.client.model.ItemDTO;
import yagwl.client.model.ItemListCache;

import com.google.gwt.user.client.ui.Composite;

/**
 * Super-class of widgets to be used in master-detail scenario. Master will be
 * able to pass object to be edited, or, in case of create, master will be able
 * to pass the list where created object needs to be appended to.
 */
public abstract class AbstractItemDetail extends Composite {
  private ItemDTO itemDTO;
  private String itemId;
  private ItemListCache listCache;

  /**
   * Sets the item to be edited
   */
  public void setItemDTO(ItemDTO itemDTO) {
    this.itemDTO = itemDTO;
  }

  public ItemDTO getItemDTO() {
    return itemDTO;
  }

  /**
   * Sets the item id of the item to be edited. In case item to be edited is not
   * available in cache, the item needs to be fetched from the database with the
   * item id.
   */
  public void setItemId(String itemId) {
    this.itemId = itemId;
  }

  public String getItemId() {
    return itemId;
  }

  public ItemListCache getListCache() {
    return listCache;
  }

  /**
   * Sets the ItemListCache where a newly created item is to be cached. Consumers of
   * AbstractItemDetail may need to fetch the created item from the database if
   * there are server generated attributes.
   */
  public void setListCache(ItemListCache listCache) {
    this.listCache = listCache;
  }

}
